<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>外卖柜后台管理系统</title>
<link rel="icon" href="favicon.ico" th:href="@{/favicon.ico}" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/materialdesignicons.min.css" rel="stylesheet">
<!--  动画样式-->
  <link href="/css/animate.css" rel="stylesheet">
<link href="/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <aside class="lyear-layout-sidebar">
      
      <!-- logo -->
      <div id="logo" class="sidebar-header">
        <a th:href="@{/admin/index}"><img src="/images/logo-sidebar.png" title="LightYear" alt="LightYear" width="220px"/></a>
      </div>
      <div class="lyear-layout-sidebar-scroll"> 
        
        <nav class="sidebar-main">
          <ul class="nav nav-drawer">
            <li class="nav-item active"> <a href="index.html" th:href="@{/admin/index}"><i class="mdi mdi-home"></i> 存柜总览</a> </li>
          </ul>
        </nav>
        
        <div class="sidebar-footer">
          <p class="m-b-0">Copyright © 2022 <a href="https://gitee.com/hzf2281" target="_blank">code咸鱼</a>. All right reserved</p>
        </div>
      </div>
      
    </aside>
    <!--End 左侧导航-->
    
    <!--头部信息-->
    <header class="lyear-layout-header">
      
      <nav class="navbar navbar-default">
        <div class="topbar">
          
          <div class="topbar-left">
            <div class="lyear-aside-toggler">
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
            </div>
            <span class="navbar-page-title"> 后台首页 </span>
          </div>
          
          <ul class="topbar-right">
            <li class="dropdown dropdown-profile">
              <a href="javascript:void(0)" data-toggle="dropdown">
                <img class="img-avatar img-avatar-48 m-r-10" src="/images/users/avatar.jpg" alt="笔下光年">
                <span th:text="${#session.getAttribute('username')}">笔下光年 <span class="caret"></span></span>
              </a>
              <ul class="dropdown-menu dropdown-menu-right">
                <li> <a href="lyear_pages_edit_pwd.html" data-toggle="modal" data-target="#changePswModal"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
                <li class="divider"></li>
                <li> <a href="lyear_pages_login.html" th:href="@{/admin/quitLogin}"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
              </ul>
            </li>
            <!--切换主题配色-->
		    <li class="dropdown dropdown-skin">
			  <span data-toggle="dropdown" class="icon-palette"><i class="mdi mdi-palette"></i></span>
			  <ul class="dropdown-menu dropdown-menu-right" data-stoppropagation="true">
                <li class="drop-title"><p>主题</p></li>
                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="site_theme" value="default" id="site_theme_1" checked>
                    <label for="site_theme_1"></label>
                  </span>
                  <span>
                    <input type="radio" name="site_theme" value="dark" id="site_theme_2">
                    <label for="site_theme_2"></label>
                  </span>
                  <span>
                    <input type="radio" name="site_theme" value="translucent" id="site_theme_3">
                    <label for="site_theme_3"></label>
                  </span>
                </li>
			    <li class="drop-title"><p>LOGO</p></li>
				<li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="logo_bg" value="default" id="logo_bg_1" checked>
                    <label for="logo_bg_1"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_2" id="logo_bg_2">
                    <label for="logo_bg_2"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_3" id="logo_bg_3">
                    <label for="logo_bg_3"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_4" id="logo_bg_4">
                    <label for="logo_bg_4"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_5" id="logo_bg_5">
                    <label for="logo_bg_5"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_6" id="logo_bg_6">
                    <label for="logo_bg_6"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_7" id="logo_bg_7">
                    <label for="logo_bg_7"></label>
                  </span>
                  <span>
                    <input type="radio" name="logo_bg" value="color_8" id="logo_bg_8">
                    <label for="logo_bg_8"></label>
                  </span>
				</li>
				<li class="drop-title"><p>头部</p></li>
				<li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="header_bg" value="default" id="header_bg_1" checked>
                    <label for="header_bg_1"></label>                      
                  </span>                                                    
                  <span>                                                     
                    <input type="radio" name="header_bg" value="color_2" id="header_bg_2">
                    <label for="header_bg_2"></label>                      
                  </span>                                                    
                  <span>                                                     
                    <input type="radio" name="header_bg" value="color_3" id="header_bg_3">
                    <label for="header_bg_3"></label>
                  </span>
                  <span>
                    <input type="radio" name="header_bg" value="color_4" id="header_bg_4">
                    <label for="header_bg_4"></label>                      
                  </span>                                                    
                  <span>                                                     
                    <input type="radio" name="header_bg" value="color_5" id="header_bg_5">
                    <label for="header_bg_5"></label>                      
                  </span>                                                    
                  <span>                                                     
                    <input type="radio" name="header_bg" value="color_6" id="header_bg_6">
                    <label for="header_bg_6"></label>                      
                  </span>                                                    
                  <span>                                                     
                    <input type="radio" name="header_bg" value="color_7" id="header_bg_7">
                    <label for="header_bg_7"></label>
                  </span>
                  <span>
                    <input type="radio" name="header_bg" value="color_8" id="header_bg_8">
                    <label for="header_bg_8"></label>
                  </span>
				</li>
				<li class="drop-title"><p>侧边栏</p></li>
				<li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="sidebar_bg" value="default" id="sidebar_bg_1" checked>
                    <label for="sidebar_bg_1"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_2" id="sidebar_bg_2">
                    <label for="sidebar_bg_2"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_3" id="sidebar_bg_3">
                    <label for="sidebar_bg_3"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_4" id="sidebar_bg_4">
                    <label for="sidebar_bg_4"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_5" id="sidebar_bg_5">
                    <label for="sidebar_bg_5"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_6" id="sidebar_bg_6">
                    <label for="sidebar_bg_6"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_7" id="sidebar_bg_7">
                    <label for="sidebar_bg_7"></label>
                  </span>
                  <span>
                    <input type="radio" name="sidebar_bg" value="color_8" id="sidebar_bg_8">
                    <label for="sidebar_bg_8"></label>
                  </span>
				</li>
			  </ul>
			</li>
            <!--切换主题配色-->
          </ul>
          
        </div>
      </nav>

    </header>
    <!--End 头部信息-->
    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid">

<!--        数据快速总览-->
        <div class="row">
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-primary">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">空柜数量</p>
                  <p class="h3 text-white m-b-0 fa-1-5x" th:text="${#session.getAttribute('cabStateCount1')}">102,125.00</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-checkbox-marked-circle-outline fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-info">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">12h内存柜数量</p>
                  <p class="h3 text-white m-b-0 fa-1-5x" th:text="${#session.getAttribute('cabStateCount2')}">920,000</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-leaf fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-danger">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">超时存柜数量</p>
                  <p class="h3 text-white m-b-0 fa-1-5x" th:text="${#session.getAttribute('cabStateCount3')}">34,005,000</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-alert-outline fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-pink">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">存取记录总数</p>
                  <p class="h3 text-white m-b-0 fa-1-5x"><span th:text="${#session.getAttribute('historyCount')}">153</span> 条</p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-information-outline fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
        </div>
        <!--        end-数据快速总览-->

<!--        存取记录统计-->
        <div class="row">
          <div class="col-lg-6">
            <div class="card">
              <div class="card-header">
                <h4>存取记录统计</h4>
              </div>
              <div class="card-body">
                <canvas class="js-chartjs-bars"></canvas>
              </div>
            </div>
          </div>
        </div>
<!--        end-存取记录统计-->

<!--        存柜详情-->
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header">
                <h4>存柜详情</h4>
              </div>
              <div class="card-body">
<!--                搜索框-->
                <form method="post" class="form-inline" th:action="@{/admin/selectById#main-table}" role="form">
                  <div class="input-group">
                    <span class="input-group-addon" id="search-bar">柜号</span>
                    <input type="text" class="form-control" value="" name="id" placeholder="请输入柜号" aria-describedby="search-bar">
                  </div>
                  <div class="input-group">
                    <button type="submit" class="btn btn-success btn-w-xs">搜索</button>
                  </div>
                  <div class="input-group" style="float: right">
                    <a th:href="@{#main-table}">
                      <button class="btn btn-pink btn-round" type="button">搜索模式<i th:if="${queryMode!=null}" class="mdi mdi-eye"></i></button>
                    </a>
                    <a th:href="@{/admin/index#main-table}">
                      <button class="btn btn-primary btn-round" type="button">全部<i th:if="${code==null&&queryMode==null}" class="mdi mdi-eye"></i></button>
                    </a>
                    <a th:href="@{/admin/filterByState#main-table(code=1)}">
                      <button class="btn btn-default btn-round" type="button">空柜<i th:if="${code==1}" class="mdi mdi-eye"></i></button>
                    </a>
                    <a th:href="@{/admin/filterByState#main-table(code=2)}">
                      <button class="btn btn-info btn-round"  type="button">已存柜<i th:if="${code==2}" class="mdi mdi-eye"></i></button>
                    </a>
                    <a th:href="@{/admin/filterByState#main-table(code=3)}">
                      <button class="btn btn-danger btn-round"  type="button">已存且满12h未取出<i th:if="${code==3}" class="mdi mdi-eye"></i></button>
                    </a>
                  </div>
                </form>
<!--                信息表-->
                <div class="table-responsive">
                  <table class="table table-hover" id="main-table">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>存柜编号</th>
                        <th>存柜状态</th>
                      </tr>
                    </thead>
                    <tbody>
                    <tr th:each="item,varState : ${records}">
                      <td th:text="${varState.count+firstIndex}">1</td>
                      <td th:text="${item.serialNumber}">1-1-0001</td>
                      <td th:if="${item.stateCode==1}" ><img th:src="@{/images/cabinet/cabinet-{status}.png(status=${item.stateCode})}" alt="空柜" title="空柜" width="30em" height="30em"/></td>
                      <td th:if="${item.stateCode==2}"><img  th:src="@{/images/cabinet/cabinet-{status}.png(status=${item.stateCode})}" alt="已存柜" title="已存柜" width="30em" height="30em"/></td>
                      <td th:if="${item.stateCode==3}"><img  th:src="@{/images/cabinet/cabinet-{status}.png(status=${item.stateCode})}" alt="存柜超过12h" title="存柜超过12h" width="30em" height="30em"/></td>
                    </tr>
                    </tbody>
                  </table>
                  <form class="form-inline" method="post" action="#" th:if="${queryMode!=null&&records!=null}">
                    <div class="form-group">
                      操作:
                      <button class="btn btn-primary" type="button" onclick="openDoor('外侧')">打开外侧柜门</button>
                      <button class="btn btn-info" type="button" onclick="openDoor('内侧')">打开内侧柜门</button>
                      <button class="btn btn-success"  th:onclick="sendMail(1,[[${searchId}]])" type="button" th:if="${records.getStateCode()==2}">发送取餐提醒短信</button>
                      <button class="btn btn-danger"   th:onclick="sendMail(2,[[${searchId}]])" type="button" th:if="${records.getStateCode()==3}">发送超时清除提醒短信</button>
                    </div>
                  </form>
                </div>
<!--                分页条-->
                <nav th:if="${totalPage>1}">
                  <ul class="pagination pagination-lg">
                    <li th:class="${pid==1? 'disabled':''}">
                      <a th:onclick="|javascript:return ${pid!=1}|" th:href="@{/admin/{url}#main-table(pid=${pid+-1},maxNum=${pageSize},url=${url},code=${code})}">
                        <span><i class="mdi mdi-chevron-left"></i></span>
                      </a>
                    </li>
                    <li th:each="index :${#numbers.sequence(1,totalPage)}" th:class="${index==pid? 'active':''}">
                      <a th:href="@{/admin/{url}#main-table(pid=${index},maxNum=${pageSize},url=${url},code=${code})}" th:text="${index}"></a>
                    </li>
                    <li th:class="${pid==totalPage? 'disabled':''}">
                      <a th:onclick="|javascript:return ${pid!=totalPage}|"  th:href="@{/admin/{url}#main-table(pid=${pid+1},maxNum=${pageSize},url=${url},code=${code})}">
                        <span><i class="mdi mdi-chevron-right"></i></span>
                      </a>
                    </li>
                  </ul>
                </nav>
              </div>
            </div>
          </div>
          
        </div>
<!--        end-存柜详情-->
      </div>
      <!--                修改密码模态框-->
      <div class="modal fade" id="changePswModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">修改密码</h4>
            </div>
            <div class="modal-body">
             <div class="form-group">
               <label for="oldPassword">旧密码：</label>
               <input type="password" id="oldPassword" class="form-control" placeholder="请输入旧密码"/>
             </div>
              <div class="form-group">
                <label for="newPassword">新密码：</label>
                <input type="password" id="newPassword" class="form-control" placeholder="请输入新密码"/>
              </div>
              <div class="form-group">
                <label for="confirmPassword">确认密码：</label>
                <input type="password" id="confirmPassword" class="form-control" placeholder="请再次输入新密码"/>
              </div>
            </div>
            <span id="tipMsg" style="font-size: small;font-weight: bold;color: red"></span>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-primary" onclick="changePsw()">确认修改</button>
            </div>
          </div>
        </div>
      </div>
      <!--                end修改密码模态框-->
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
<!--消息提示插件-->
<script src="/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/js/lightyear.js"></script>
<script type="text/javascript" src="/js/main.min.js"></script>
<script type="text/javascript">
  //发送取餐短信
  var sendMail=function (mode,id){
    lightyear.loading('show');
    $.ajax({
      url: `/admin/sendMail`,
      type:'GET',
      dataType: 'json',
      async:true,
      data:{
        mailMode: mode,
        cabId: id
      },
      success: function(res){
        lightyear.loading('hide');
        if(res.result!=null&& res.result==true){
          lightyear.notify(`成功向手机号码${res.telNum}发送${res.mode==1? '取餐提醒':'超12h清除'}短信`,'success',2000);
        }else{
          lightyear.notify(`服务器发送错误，无法发送短信，请联系<a href="https://gitee.com/hzf2281" target="_blank">维护人员</a>`,'danger',2000);
        }
      },
      error:function () {
        lightyear.loading('hide');
        lightyear.notify(`服务器发送错误，无法发送短信，请联系<a href="https://gitee.com/hzf2281" target="_blank">维护人员</a>`,'danger',2000);
     }
    })
  }
  //模拟打开柜门
  var openDoor=function (position){
    lightyear.notify(position+'柜门已打开，请及时关闭','success',1000);
  }
</script>
<!--修改密码-->
<script type="text/javascript">

  var changePsw=function (){
    let oldPassword=$('#oldPassword').val();
    let newPassword=$('#newPassword').val();
    let confirmPassword=$('#confirmPassword').val();
    let tipElement=$('#tipMsg');
    if(oldPassword==""){
      tipElement.text('旧密码不能为空');
      return;
    } else if(newPassword==""){
      tipElement.text('新密码不能为空');
      return;
    }else if(newPassword!=confirmPassword){
      tipElement.text('两次密码不一致！');
      return;
    }else{
      $.ajax({
        url:'/admin/changePassword',
        type:'POST',
        dataType: 'json',
        data:{
          newPassword:newPassword,
          oldPassword:oldPassword
        },
        success: function(res){
          if(res==true){
            //修改密码成功
            //设置登录页倒计时跳转指示秒数
            let tick=3;
            //倒计时提示
            tipElement.text(`密码修改成功,请重新登录。${tick--}s后自动跳转登录页`);
            window.setInterval(()=>{
              tipElement.text(`密码修改成功,请重新登录。${tick--}s后自动跳转登录页`);
            },1000);
            //3s后跳转登录页
             window.setTimeout(()=>{
               window.location.href ='/admin/login';
             },3000);
          }else{
            //修改密码失败
            tipElement.text('旧密码错误！');
          }
        }
      })
    }

  }
</script>


<!--图表插件-->
<script type="text/javascript" src="/js/Chart.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    var $dashChartBarsCnt  = jQuery( '.js-chartjs-bars' )[0].getContext( '2d' );
    var weekData=[0,0,0,0,0,0,0];
    var url=`/admin/countByWeek`;
    $.ajax({
       url:url,
       async:false,
       type:'GET',
       success:function(data){
         weekData=data;
       }
    })
    
    var $dashChartBarsData = {
		labels: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
		datasets: [
			{
				label: '存取记录数',
                borderWidth: 1,
                borderColor: 'rgba(0,0,0,0)',
				backgroundColor: 'rgba(51,202,185,0.5)',
                hoverBackgroundColor: "rgba(51,202,185,0.7)",
                hoverBorderColor: "rgba(0,0,0,0)",
				data: weekData
			}
		]
	};

    
    new Chart($dashChartBarsCnt, {
        type: 'bar',
        data: $dashChartBarsData
    });
    

});
</script>
</body>
</html>